package cn.edu.hrbcu.es.invigilatemanagerment.service;

import cn.edu.hrbcu.es.invigilatemanagerment.dao.RoleMapper;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.Role;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.RoleExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements IRoleService{
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public Integer insertRole(Role role) {
        return roleMapper.insert(role);
    }

    @Override
    public Integer deleteRoleByPrimaryId(Integer roleId) {
        return roleMapper.deleteByPrimaryKey(roleId);
    }

    @Override
    public Integer updateRoleByPrimaryId(Role role) {
        return roleMapper.updateByPrimaryKey(role);
    }

    @Override
    public List<Role> queryRolesByIds(List<Integer> ids) {
        return null;
    }

    @Override
    public List<Role> queryAllRole() {
        RoleExample roleExample = new RoleExample();
        RoleExample.Criteria criteria = roleExample.createCriteria();
        criteria.getAllCriteria();
        return roleMapper.selectByExample(roleExample);
    }

    @Override
    public Role queryRoleById(Integer id) {
        return roleMapper.selectByPrimaryKey(id);
    }

    @Override
    public int queryRoleCount() {
        RoleExample roleExample = new RoleExample();
        RoleExample.Criteria criteria = roleExample.createCriteria();
        criteria.getAllCriteria();
        return (int) roleMapper.countByExample(roleExample);
    }

    @Override
    public List<Role> queryRolesByPgae(int pageNow, int pageSize) {
        PageHelper.startPage(pageNow,pageSize);
        List<Role> roles = this.queryAllRole();
        PageInfo<Role> rolePageInfo = new PageInfo<>(roles);
        return rolePageInfo.getList();
    }
}
